package com.example.shopp_2301.category

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.example.base.entity.CategoryEntity
import com.example.base.entity.GoodsEntity
import com.example.base.mvvm.BaseModel
import com.example.base.mvvm.BaseViewModel
import kotlinx.coroutines.launch

class CategoryViewModel:BaseViewModel() {
    //返回值-----一级分类和二级分类
    val cateSuccess = MutableLiveData<BaseModel<CategoryEntity>>()
    val cateFail = MutableLiveData<String>()
    fun category(){
        viewModelScope.launch {
            try {
                cateSuccess.value = apiServer.category()
            }catch (e:Exception){
                cateFail.value =e.message
            }
        }
    }
    //返回值--商品列表
    val goodsSuccess = MutableLiveData<BaseModel<GoodsEntity>>()
    val goodsFail = MutableLiveData<String>()
    fun categoryGoods(cid:Int,limit:Int,page:Int){
        viewModelScope.launch {
            try {
                goodsSuccess.value = apiServer.cateGoryGoods(cid,limit, page)
            }catch (e:Exception){
                goodsFail.value = e.message
            }
        }
    }
}